package net.jjjshop.common.util;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;


/**
 * @Description: 常用工具类
 * @Author: zouqh
 * @Date: 10:23 2023/2/18
 * @Version:
 */
public class BigDecimalUtil {




    /**
     * 加法运算

     * @return
     */
    public static BigDecimal addDouble(BigDecimal bigDecimal1 , BigDecimal bigDecimal2) {
        return bigDecimal1.add(bigDecimal2);
    }

    /**
     * 减法运算
     * @return
     */
    public static BigDecimal subDouble(BigDecimal bigDecimal1 , BigDecimal bigDecimal2) {
        return bigDecimal1.subtract(bigDecimal2);
    }

    /**
     * 乘法运算
     * @return
     */
    public static BigDecimal mul(BigDecimal bigDecimal1 , BigDecimal bigDecimal2) {
        return bigDecimal1.multiply(bigDecimal2);
    }

    /**
     * 除法运算
     * @return
     */
    public static BigDecimal divide(BigDecimal bigDecimal1 , BigDecimal bigDecimal2) {
        return bigDecimal1.divide(bigDecimal2, 2, BigDecimal.ROUND_HALF_UP);
    }


    /**
     * 获取当年的第一天
     * @param
     * @return
     */
    public static String getCurrYearFirst(){
        Calendar currCal= Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return getYearFirst(currentYear);
    }

    /**
     * 获取当年的第一天
     * @param
     * @return
     */
    public static int getCurrYear(){
        Calendar currCal= Calendar.getInstance();
        int currentYear = currCal.get(Calendar.YEAR);
        return currentYear;
    }

    /**
     * 获取某年第一天日期
     * @param year 年份
     * @return Date
     */
    public static String getYearFirst(int year){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        Date currYearFirst = calendar.getTime();
        String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(currYearFirst);

        return nowTime;
    }

    /**
     * 获取几周前的时间
     * @param week
     * @return
     */
    public static String getTwoWeek(int week){
        LocalDate localDate = LocalDate.now().minusWeeks(week);
        return localDate.toString();
    }
}
